home *** CD-ROM | disk | FTP | other *** search
- ## -*-Tcl-*-
- # ###################################################################
- # AlphaTcl - core Tcl engine
- #
- # FILE: "search.tcl"
- # created: 13/6/95 {8:56:37 pm}
- # last update: 01/25/2001 {23:26:54 PM}
- #
- # Reorganisation carried out by Vince Darley with much help from Tom
- # Fetherston, Johan Linde and suggestions from the Alpha-D mailing list.
- # Alpha is shareware; please register with the author using the register
- # button in the about box.
- #
- # Description:
- #
- # All procedures which deal with search/reg-search/grep type stuff
- # in Alpha.
- # ###################################################################
- ##
-
- namespace eval text {}
- namespace eval quote {}
- namespace eval file {}
- namespace eval search {}
-
- proc quickFind {} {search::interactive exact}
- proc reverseQuickFind {} {search::interactive exact 0}
- proc quickFindRegexp {} {search::interactive regexp}
-
- #================================================================================
- # 'greplist' and 'grepfset' are used for batch searching from the "find" dialog.
- # Hence, you really shouldn't mess with them unless you know what you are doing.
- #================================================================================
- proc greplist {args} {
- global tileLeft tileTop tileWidth tileHeight errorHeight
-
- set recurse [lindex $args 0]
- set word [lindex $args 1]
- set args [lrange $args 2 end]
-
- set num [expr {[llength $args] - 2}]
- set exp [lindex $args $num]
- set arglist [lindex $args [expr {$num + 1}]]
-
- set opened 0
- set cid [scancontext create]
-
- set cmd [lrange $args 0 [expr {$num - 1}]]
- eval scanmatch $cmd {$cid $exp {
- if {!$word || [regexp -nocase -- "(^|\[^a-zA-Z0-9\])${exp}(\[^a-zA-Z0-9\]|\$)" $matchInfo(line)]} {
- if {!$opened} {
- set opened 1
- win::SetProportions
- set w [new -n {* Batch Find *} -m Brws -g $tileLeft $tileTop $tileWidth $errorHeight -tabsize 8]
- insertText "(<cr> to go to match)\r-----\r"
- }
- set l [expr {20 - [string length [file tail $f]]}]
- regsub -all "\t" $matchInfo(line) " " text
- insertText -w $w "\"[file tail $f]\"[format "%$l\s" ""]; Line $matchInfo(linenum): ${text}\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t∞$f\r"}
- }
- }
-
- foreach f $arglist {
- message [file tail $f]
- if {![catch {set fid [alphaOpen $f]}]} {
- scanfile $cid $fid
- close $fid
- }
- }
- scancontext delete $cid
-
- if {$opened} {
- select [nextLineStart [nextLineStart [minPos]]] [nextLineStart [nextLineStart [nextLineStart [minPos]]]]
- setWinInfo dirty 0
- setWinInfo read-only 1
- }
- message ""
- }
-
-
- ##
- # -------------------------------------------------------------------------
- #
- # "grepfset" --
- #
- # args: wordmatch ?-nocase? expression fileset
- # Obviously we ignore wordmatch
- #
- # If the 'Grep' box was set, then the search item is _not_ quoted.
- #
- # Non grep searching problems:
- #
- # If it wasn't set, then some backslash quoting takes place.
- # (The chars: \.+*[]$^ are all quoted)
- # Unfortunately, this latter case is done incorrectly, so most
- # non-grep searches which contain a grep-sensitive character fail.
- # The quoting should use the equivalent of the procedure 'quote::Regfind'
- # but it doesn't quote () and perhaps other important characters.
- #
- # Even worse, if the string contained any '{' it never reaches this
- # procedure (there must be an internal error due to bad quoting).
- #
- # -------------------------------------------------------------------------
- ##
- proc grepfset {args} {
- set num [expr {[llength $args] - 2}]
- # the 'find' expression
- set exp [lindex $args $num]
- # the fileset
- set fset [lindex $args [expr {$num + 1}]]
- eval greplist 0 [lrange $args 0 [expr {$num-1}]] {$exp [getFileSet $fset]}
- }
-
- proc grep {exp args} {
- set files {}
- foreach arg $args {
- eval lappend files [glob -types TEXT -nocomplain -- $arg]
- }
- if {![llength $files]} {return "No files matched pattern"}
- set cid [scancontext create]
- scanmatch $cid $exp {
- if {!$blah} {
- set blah 1
- set lines "(<cr> to go to match)\n"
- }
- set l [expr {20 - [string length [file tail $f]]}]
- regsub -all "\t" $matchInfo(line) " " text
- append lines "\"[file tail $f]\"[format "%$l\s" ""]; Line $matchInfo(linenum): ${text}\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t∞$f\n"
- }
-
- set blah 0
- set lines ""
-
- foreach f $files {
- if {![catch {set fid [alphaOpen $f]}]} {
- message [file tail $f]
- scanfile $cid $fid
- close $fid
- }
- }
- scancontext delete $cid
- return [string trimright $lines "\r"]
- }
-
- proc grepnames {exp args} {
- set files {}
- foreach arg $args {
- eval lappend files [glob -types TEXT -nocomplain -- $arg]
- }
- if {![llength $files]} {return "No files matched pattern"}
- set cid [scancontext create]
- scanmatch $cid $exp {
- lappend filenames $f
- }
- set filenames ""
- foreach f $files {
- if {![catch {set fid [alphaOpen $f]}]} {
- message [file tail $f]
- scanfile $cid $fid
- close $fid
- }
- }
- scancontext delete $cid
- return $filenames
- }
-
- ##
- # -------------------------------------------------------------------------
- #
- # "performSearch" --
- #
- # Call this procedure in Tcl code which wants to use the standard procs
- # like 'replaceAll' to ensure flags like multi-file batch replace are
- # cleared. Otherwise replaceAll might not have the desired effect.
- #
- # This proc is overridden by code (such as supersearch) which might
- # otherwise cause the nasty behaviour.
- # -------------------------------------------------------------------------
- ##
- proc performSearch {args} {
- eval select [uplevel 1 search $args]
- }
-
- proc findBatch {forward ignore regexp word pat} {
- matchingLines $pat $forward $ignore $word $regexp
- }
-
- ##
- # -------------------------------------------------------------------------
- #
- # "containsSpace" --
- #
- # Does the given text contain any spaces? In general we don't
- # complete commands which contain spaces (although perhaps future
- # extensions should do this: e.g. cycle through 'string match',
- # 'string compare',…)
- #
- # -------------------------------------------------------------------------
- ##
- proc containsSpace { cmd } { return [string match "*\[ \t\]*" $cmd] }
- proc containsReturn { cmd } { return [string match "*\[\r\n\]*" $cmd] }
-
- ##
- # -------------------------------------------------------------------------
- #
- # "findPatJustBefore" --
- #
- # Utility proc to check whether the first occurrence of 'findpat' to
- # the left of 'pos' is actually an occurrence of 'pat'. It can be
- # used to check if we're part of an '} else {' (see TclelectricLeft)
- # or in TeX mode if we're in the argument of a '\label{' or '\ref{'
- # (see smartScripts) for example.
- #
- # A typical usage has the regexp 'pat' end in '$', so that it must
- # match all the text up to 'pos'. 'matchw' can be used to store the
- # first '()' pair match in the regexp.
- #
- # New: maxlook restricts how far this proc will search. The default
- # is only 100 (not the entire file), after all this proc is supposed
- # to look 'just before'!
- # -------------------------------------------------------------------------
- ##
- proc findPatJustBefore { findpat pat {pos ""} {matchw ""} {maxlook 100} } {
- if { $pos == "" } {set pos [getPos] }
- if {[pos::compare $pos == [maxPos]]} { set pos [pos::math $pos - 1]}
- if { $matchw != "" } { upvar $matchw word }
- if {[llength [set res [search -s -n -f 0 -r 1 -l [pos::math $pos - $maxlook] -- "$findpat" $pos]]]} {
- if {[regexp -- "$pat" [getText [lindex $res 0] $pos] dum word]} {
- return [lindex $res 0]
- }
- }
- return
- }
- # Look for pattern in filename after position afterPos and, if found,
- # open the file quietly and select the pattern
- # author Jonathan Guyer
- proc selectPatternInFile {filename pattern {afterPos ""}} {
- if {$afterPos == ""} {set afterPos [minPos]}
- set searchResult [searchInFile $filename $pattern 1]
- if {[pos::compare [lindex $searchResult 0] >= $afterPos]} {
- placeBookmark
- file::openQuietly $filename
- eval select $searchResult
- message "press <Ctrl .> to return to original cursor position"
- return 1
- } else {
- return 0
- }
- }
-
- proc text::replace {old new {fwd 1} {pos ""}} {
- if {$pos == ""} {set pos [getPos]}
- set m [search -s -f $fwd -m 0 -r 0 -- $old $pos]
- eval replaceText $m [list $new]
- }
-
- proc isSelection {} {
- return [pos::compare [getPos] != [selEnd]]
- }
- proc searchStart {} {
- global search_start
- select [getPos]
- setMark
- if {[catch {goto $search_start}]} {message "No previous search"}
- }
- set {patternLibrary(Pascal to C Comments)} { {\{([^\}]*)\}} {/* \1 */} }
- set {patternLibrary(C++ to C Comments)} { {//(.*)} {/* \1 */} }
- set {patternLibrary(Space Runs to Tabs)} { { +} {\t}}
-
- proc getPatternLibrary {} {
- global patternLibrary
-
- foreach nm [array names patternLibrary] {
- lappend nms [concat [list $nm] $patternLibrary($nm)]
- }
- return $nms
- }
-
- # This fails if, say, search string is '\{[^}]'
- # This is because the '}' ends the first argument because this
- # procedure is presumably called internally with incorrect quoting.
- proc rememberPatternHook {search replace} {
- global patternLibrary modifiedArrayElements
- if {[catch {set name [prompt "New pattern's name?" ""]}]} {
- return ""
- }
- lappend modifiedArrayElements [list $name patternLibrary]
- set patternLibrary($name) [list $search $replace]
- return $name
- }
-
- proc deletePatternHook {} {
- global patternLibrary modifiedArrayElements
- set temp [list prompt "Delete which pattern?" [lindex [array names patternLibrary] 0] "Pats:"]
- set name [eval [concat $temp [array names patternLibrary]]]
- lappend modifiedArrayElements [list $name patternLibrary]
- unset patternLibrary($name)
- }
-
-
- ##
- # -------------------------------------------------------------------------
- #
- # "search::interactive" -- general interactive searching
- #
- # This version allows class shorthands (\d \s \w \D \S \W),
- # word anchors (\b), and some aliases of the machine dependent
- # control characters (\a \f \e \n \r \t). Therefore,
- # we need two prompts, one for when we have a valid pattern, and one
- # for when the pattern has gone invalid (most likely due to starting
- # to enter one of the above patterns).
- #
- # The Return key and unknown key combinations exit the search, leaving
- # the point at its current position. You can then use 'exchangePointAndMark'
- # (cntrl-x, cntrl-x -in emacs keyset) to jump back and forth between where
- # the search started from and where the search ended.
- #
- # Known key combinations (e.g., arrow keys, many emacs navigation keys)
- # exit the search and perform the appropriate action. The mark is set to
- # the last successful search, so 'exchangePointAndMark' does NOT take you
- # to the start of the search.
- #
- # The Escape key or abortEm (cntrl-g in emacs) "aborts" the search,
- # returning the cursor to the point where the search started from.
- # Use 'exchangePointAndMark' to jump to the last found match.
- #
- # The next occurrence of the current pattern can be matched by typing
- # either control-s (to get the next occurence forward), or control-r
- # (to get the the next occurrence backward)
- #
- # Also, after aborting or exiting, the search string is left in the Find
- # dialog, and so you can use 'findAgain' or cntrl-s or cntrl-r to continue
- # the search. Be aware that the Find dialog starts out with a default of
- # <Grep=OFF>.
- #
- # Original Author: Mark Nagata
- # modifications : Tom Fetherston
- # modifications : Vince Darley, so works with or without regexp
- # -------------------------------------------------------------------------
- ##
-
- proc search::interactive {{type "exact"} {direction 1}} {
- set ignoreCase 1
- set interpretBackslash 0
- set patt ""
- set pos [getPos]
- lappend history [list "" [list $pos $pos] 1]
-
- set done 0
- while {!$done} {
- if {$type == "regexp"} {
- # check pattern validatity
- if {[catch {regexp -- $patt {} dmy} dmy]} {
- set prompt "building->: $patt"
- } else {
- set prompt "regIsearch: $patt"
- }
- } else {
- set prompt "search: $patt"
- }
- set proc [list search::interactiveKeypress $type $direction]
- set done 1
- switch -- [catch [list status::prompt -appendvar patt -command $proc -add anything $prompt] res] {
- 0 {
- # got a keystroke that triggered a normal end (e.g. <return>)
- set res "<return>"
- set tmp [getPos]
- goto $pos
- setMark
- goto $tmp
- }
- 1 {
- # an error was generated
- if {[string match "missing close-brace" $res]} {
- # must have typed a slash, so:
- append patt "\\"
- set done 0
- } elseif {[string match "invoked \"break\" outside of a loop" $res]} {
- # do nothing
- } elseif {[string match "abort*" $res]} {
- if {[package::active emacs]} { append res ". ctrl-x ctrl-x goes to last found" }
- goto $pos
- } elseif {[string match "unknown*" $res]} {
- if {[package::active emacs]} { append res ". ctrl-x ctrl-x goes to search start" }
- set tmp [getPos]
- goto $pos
- setMark
- goto $tmp
- } else {
- # unknown error -- exit
- }
- }
- default {
- set done 1
- }
- }
- }
- message "Search $patt: exited with $res."
- }
-
- ##
- # -------------------------------------------------------------------------
- #
- # "search::interactiveKeypress" -- handle isearch, rsearch, regIsearch
- #
- # This proc handles each keypress while running a regIsearch. It has been
- # modified from Mark Nagata's original to provide next ocurrence
- # before/after current, and support for key bindings whose navigation or
- # text manipulation functionality makes sense with respect to a regIsearch.
- #
- # closest occurence before current match
- # - command-option g & cntrl-r (mnemonic 'reverse')
- # closest occurence after current match
- # - command g & cntrl-s (mnemonic 'successor')
- #
- # Text Naviagation
- # forwardChar (aborts and leaves cursor after last match)
- # - right arrow & cntrl-f (emacs)
- # backwardChar (aborts and leaves cursor before last match)
- # - left arrow & cntrl-b (emacs)
- # beginningOfLine (aborts and moves cursors to the start of the line
- # containing the last match)
- # - cmd left arrow & cntrl-a (emacs)
- # beginningOfLine (aborts and moves cursors to the start of the line
- # containing the last match)
- # - cmd right arrow & cntrl-e (emacs)
- # centerRedraw (moves selection to center, without aborting)
- # - cntrl-l
- # insertToTop (moves selection to top, without aborting)
- # - cntrl-t
- # ctrl-w adds the rest of the current word to the search string.
- #
- # Text Manipulation
- # deleteSelection (aborts and deletes selection)
- # - cntrl-d (emacs)
- # killLine (aborts and deletes from start of selection to end of line)
- # - cntrl-k (emacs)
- #
- # Changing the search type:
- #
- # ctrl-i switches the case-sensitivity of the current search
- # ctrl-backslash toggles interpretation of \n,\r,\t in non-regexp searches
- # -------------------------------------------------------------------------
- ##
- proc search::interactiveKeypress {type dir {key 0} {mod 0}} {
- set direction {}
-
- # build a string that represents all the modifiers pressed:
- # checking in this order cmd, shift, option, and ctrl
- if {[expr {$mod & 1}]} { append t "c" } else { append t "_" }
- if {[expr {$mod & 34}]} { append t "s" } else { append t "_" }
- if {[expr {$mod & 72}]} { append t "o" } else { append t "_" }
- if {[expr {$mod & 144}]} { append t "z" } else { append t "_" }
- if {[string length $key]} {
- scan $key %c decVal
- } else {
- # No key showed up. Probably running on Alphatk
- error "no key press"
- }
- #tclLog "\r$key $t $mod $decVal"
- upvar patt pat
- switch -- $t {
- "____" {
- switch -- $decVal {
- 8 {
- set len [string length $pat]
- if {$len > 0} {
- set pat [string range $pat 0 [expr {$len-2}]]
- set key ""
- set backtrack 1
- } else {
- error "deletion of all characters"
- }
- }
- 1 { beginningOfBuffer; error "navigation key"; # home; }
- 4 { endOfBuffer; error "navigation key"; # end; }
- 11 { pageBack; error "navigation key"; # page up; }
- 12 { pageForward; error "navigation key"; # page down; }
- 29 { forwardChar; error "navigation key"; # right arrow; }
- 28 { backwardChar; error "navigation key"; # left arrow; }
- 30 { previousLine; error "navigation key"; # up arrow; }
- 31 { nextLine; error "navigation key"; # down arrow; }
- 27 { error "abort (esc key)"; # escape; }
- 13 { error "<return> key"; }
- }
- }
- }
- switch -- $t {
- "____" -
- "_s__" {
- if {0 && $curr != ""} {
- while {[string compare [string range $pat [string last $curr $pat] end] $curr] != 0} {
- set newEnd [expr {[string length $pat] - 2}]
- if {$newEnd < 0} {
- error "deletion of all characters"
- }
- set pat [string range $pat 0 $newEnd]
- set backtrack 1
- }
- }
-
- set preAppend $pat
- append pat $key
- if {$type == "regexp"} {
- if {[catch {regexp -- $pat {} dmy} res]} {
- message "building->: $preAppend"
- return $key
- }
- }
- set direction $dir
- # This is a continuing search from the current point
- set inplace 1
- }
- "c___" {
- switch -- $decVal {
- 101 {
- # cmd-e = enter search string
- searchString $pat
- return {}
- }
- 103 { set direction 1; # (cmd g); }
- 28 { beginningOfLine; error "navigation key"; # cmd left arrow; }
- 29 { endOfLine; error "navigation key"; # cmd right arrow; }
- default { error "unknown cmd key" }
- }
-
- }
- "__o_" {
- if {[package::active emacs]} {
- switch -- $decVal {
- 2 - 186 { backwardWord; error "emacs delete word (opt-d)"; # opt-b; }
- 4 - 182 { deleteWord; error "emacs delete word (opt-d)"; # opt-d; }
- 6 - 196 { forwardWord; error "emacs forward word (opt-f)"; # opt-f; }
- }
- }
- }
- "___z" {
- # If the user is using the emacs key bindings, check for ones that
- # make sense. All other control key combinations abort
- if {[package::active emacs]} {
- switch -- $decVal {
- 1 { beginningOfLine; error "emacs beginning of line (cnt-a)"; # cntrl-a; }
- 2 { backwardChar; error "emacs backward char (cnt-b)"; # cntrl-b; }
- 4 { deleteSelection; error "emacs delete selection (cnt-d)"; # cntrl-d; }
- 5 { endOfLine; error "emacs end of line (cnt-e)"; # cntrl-e; }
- 6 { forwardChar; error "emacs forward char (cnt-f)"; # cntrl-f; }
- 11 - 107 { killLine; error "emacs kill line (cnt-k)"; # cntrl-k; }
- 12 - 108 { centerRedraw; return {}; # cntrl-l; }
- 14 { backwardChar; nextLine; error "emacs next line (cnt-n)"; }
- 15 { openLine; error "emacs open line (cnt-o)"; # cntrl-o; }
- 16 { backwardChar; previousLine; error "emacs previous line (cnt-p)"; }
- }
- }
- # See if user has requested to find another match, either searchForward
- # (cntrl-s) or reverseSearch (cntrl-r). Set flag accordingly
- switch -- $decVal {
- 18 - 114 - 19 - 115 {
- # (ctrl-r, ctrl-s)
- if {![string length $pat]} {
- # load previous search string if current is empty
- set pat [searchString]
- }
- switch -- $decVal {
- 18 - 114 { set direction 0; # reverse; }
- 19 - 115 { set direction 1; # forward; }
- default {}
- }
- }
- 20 - 116 {
- insertToTop; #cntl-t;
- }
- 28 {
- # ctrl-backslash : toggle \n\r\t interpretation
- upvar interpretBackslash ib
- set ib [expr {1-$ib}]
- set direction $dir
- set inplace 1
- }
- 8 - 103 {
- # cntrl-g
- error "abort (ctrl-g)"
- }
- 9 - 105 {
- # ctrl-i : change case-sensitivity
- upvar ignoreCase ign
- set ign [expr {1-$ign}]
- set direction $dir
- set inplace 1
- }
- 23 - 119 {
- # ctrl-w : add next word
- set _p [getPos]
- set _q [pos::math $_p + [string length [getSelect]]]
- goto $_q
- forwardWord
- append pat [getText $_q [getPos]]
- goto $_p
- set direction $dir
- set inplace 1
- }
- default { error "unknown cntrl key" }
- }
- }
- "c_o_" {
- switch -- $decVal {
- 169 {
- # (cmd-opt 'g')
- set direction 0
- }
- default { error "unknown cmd-option key" }
- }
-
- }
- "default" {
- error "unknown modifier key"
- }
- }
- # handle direction flag if it got set above
- if {$direction != ""} {
- if {$type == "regexp"} {
- message "regIsearch: $pat "
- } else {
- message "search: $pat "
- }
- upvar ignoreCase ign
- if {![info exists inplace]} {
- if {$direction} {
- set search_start [pos::math [getPos] + 1]
- } else {
- set search_start [pos::math [getPos] - 1]
- }
- } else {
- set search_start [getPos]
- }
- upvar history hist
- if {[info exists backtrack]} {
- while {[llength $hist] > 1} {
- set hist [lrange $hist 0 [expr {[llength $hist]} -2]]
- if {[llength $hist]} {
- set last [lindex $hist end]
- if {[llength $last] == 1} {
- # search failed
- set failed 1
- continue
- }
- # Only if we haven't failed do we check the in-place
- # flag (list index 2).
- if {![info exists failed]} {
- if {![lindex $last 2]} {
- continue
- }
- }
- break
- } else {
- # error "Probably shouldn't get here"
- # Avoid infinite loop in some odd cases.
- break
- }
- }
- set last [lindex $hist end]
- set pat [lindex $last 0]
- eval select [lindex $last 1]
- } else {
- if {$type == "regexp"} {
- set searchResult [search -n -f $direction -m 0 -i $ign -r 1 -- $pat $search_start]
- } else {
- upvar interpretBackslash ib
- if {$ib} {
- set spat $pat
- regsub -all "\\\\n" $spat "\n" spat
- regsub -all "\\\\r" $spat "\r" spat
- regsub -all "\\\\t" $spat "\t" spat
- set searchResult [search -n -f $direction -m 0 -i $ign -r 0 -- $spat $search_start]
- } else {
- set searchResult [search -n -f $direction -m 0 -i $ign -r 0 -- $pat $search_start]
- }
- }
- if {[llength $searchResult] == 0} {
- lappend hist [list "failed"]
- beep
- } else {
- lappend hist [list $pat $searchResult [info exists inplace]]
- eval select $searchResult
- }
- }
- return {}
- }
- }
-
- proc nextFunc {} {
- mode::proc searchFunc 1
- }
-
- proc prevFunc {} {
- mode::proc searchFunc 0
- }
-
- proc ::searchFunc {dir} {
- global funcExpr mode
- global ${mode}modeVars
-
- if {![info exists ${mode}modeVars(funcExpr)]} {
- # for modes that have no functions, just use filemarks
- findViaFileMarks $dir
- return
- }
-
- set pos [getPos]
- select $pos $pos
-
- if {$dir} {
- set pos [pos::math $pos + 1]
- set lastStop [maxPos]
- } else {
- set pos [pos::math $pos - 1]
- set lastStop [minPos]
- }
- if {![catch {search -s -f $dir -i 1 -r 1 -- $funcExpr $pos} res]} {
- eval select $res
- } else {
- goto $lastStop
- if {$dir} {
- message "At bottom, no more functions in this direction"
- } else {
- message "At top, no more functions in this direction"
- }
- }
- }
-
- proc findViaFileMarks {dir} {
- set pos [getPos]
- set markAbovePos ""
- set markBelowPos ""
-
- set nm [getNamedMarks]
- foreach n $nm {
- set posOf_n [lindex $n 3]
- if { $posOf_n < $pos } {
- set markAbovePos [lindex $n 0]
- } elseif { $posOf_n == $pos } {
- continue
- } else {
- set markBelowPos [lindex $n 0]
- break
- }
- }
-
- if {$dir} {
- if {$markBelowPos != ""} {
- gotoMark $markBelowPos
- }
- } else {
- if {$markAbovePos != ""} {
- gotoMark $markAbovePos
- }
- }
- }
-
- ###
- #===========================================================================
- # Juan Falgueras (7/Abril/93)
- # you only need to select (or not) text and move *forward and backward*
- # faster than iSearch (if you have there the |word wo|rd..).
- #===========================================================================
-
- proc quickSearch {dir} {
- if {[pos::compare [selEnd] == [getPos]]} {
- backwardChar
- hiliteWord
- }
- set myPos [expr {$dir ? [selEnd] : [pos::math [getPos] - 1]}]
- set text [getSelect]
- set searchResult [search -s -n -f $dir -m 0 -i 1 -r 0 $text $myPos]
- if {[llength $searchResult] == 0} {
- beep
- message [concat [expr {$dir ? "->" : "<-"}] '$text' " not found"]
- return 0
- } else {
- message [concat [expr {$dir ? "->" : "<-"}] '$text']
- eval select $searchResult
- return 1
- }
- }
-
-